<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JSON响应</title>
    <style>
        #result{
            width:200px;
            height:100px;
            border:solid 1px #89b;
        }
    </style>
</head>
<body>
    <div id="result"></div>
    <script>
        const result = document.getElementById('result');
        //绑定键盘按下事件
        window.onkeydown = function(){
            let xhr = new XMLHttpRequest()
            xhr.open('GET','http://127.0.0.1:8000/serverJson')
            xhr.responseType = 'json'
            xhr.send()
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4){
                    // let data = JSON.parse(xhr.response)
                    result.innerHTML = xhr.response.name
                }
            }

        }
    </script>
</body>
</html>